<include file="Public:header" />
    <div id="main">
    	<div class="main_left">
            <include file="Public:left" />
        </div>
        <div class="main_right">
            <div class="content">
            	<div class="content_top">我的购物车</div>
                <div class="content_news">
                    <form method="post" action="{:U('Order/index')}">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" style='text-align: center;'>
                            <tr>
                                <th><input type="checkbox" id="check"></th>
                                <th class="tLeft">商品信息</th>
                                <th>单价</th>
                                <th>数量</th>
                                <th>小计</th>
                                <th></th>
                            </tr>
                            <volist name="list" id="vo">
                                <notempty name="vo.sub_list">
                                    <tr style="background: #FFF;">
                                        <td>
                                            <input type="checkbox" name="key" value="{$vo.id}">
                                        </td>
                                        <td class="tleft">
                                            <input type="hidden" name="id[]" value="{$vo.id}">
                                            <img src="__ROOT__/Uploads{$vo.sub_list.thumb}" width="60" height="60" class="fLeft" />
                                            <div class="prolisttitle">
                                            <a href="{:U('Product/show',array('id'=>$vo['sub_list']['id']))}" target="_blank">{$vo.sub_list.title}</a>
                                            </div>
                                        </td> 
                                        <td>     
                                            ￥<span name="price">{$vo.sub_list.price}</span>
                                        </td> 
                                        <td>     
                                            <input type="text" style="width: 50px;" name="num[]" value="{$vo.num}">
                                        </td> 
                                        <td>     
                                            ￥<span name="allprice">{$vo.allprice}</span>
                                        </td>
                                        <td>     
                                            <a href="#" onclick="foreverdel({$vo['id']}); return false;">删除</a>
                                        </td>
                                    </tr>
                                </notempty>
                            </volist>
                        </table>
                        <div class='clear'></div>
                        <div class="th" style="margin-top: 5px; float: right; font-size: 14px;">合计：￥<span id="totalprice">{$totalPrice}</span></div>
                        <div class='clear'></div>
                        <div class="th" style="margin-top: 5px; float: left;">
                            <input type="button" onclick="foreverdel(); return false;" value="批量删除"  class="btn7">
                        </div>
                        <div class="th" style="margin-top: 5px; float: right;">
                            <input type="submit" value="立即订购" class="btn7">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript">
    $(function(){
        var i=0;
        $("table tr").each(function(){
            if(i>0){
                var price=$(this).children('td').next().next().children('span').html();
                var num=$(this).children('td').next().next().next().children('input').val();
                var count=accMul(num,price).toFixed(2);//计算单个物品价格
                $(this).children('td').next().next().next().next().children('span').html(count);
            }
            i++;
        });
        GetInAll();//计算所有物品价格
        
        $("table input[type=text]").blur(function(oEven){
            var price=$(this).parent().prev().children('span').html();
            var num=$(this).val();
            var count=accMul(num,price).toFixed(2);//计算单个物品价格
            $(this).parent().next().children('span').html(count);
           
            GetInAll();//计算所有物品价格
        });
    })
    
    function GetInAll(){
        var i=0;
        var totalprice=0;
        var allprice=0;
        $("table tr").each(function(){
            if(i>0){
                allprice=$(this).children('td').next().next().next().next().children('span').html();
                totalprice=accAdd(totalprice, allprice).toFixed(2);
            }
            i++;
        });
        $("#totalprice").html(totalprice);
    } 

    $(document).ready(function(){
        $("#check").attr("checked","checked");
        $('input[name=key]').attr("checked","checked");
        //全选/取消
        $("#check").click(function(){
            if($(this).attr("checked")==true){
                $('input[name=key]').attr("checked","checked");
            }else{
                $('input[name=key]').removeAttr ("checked");  
            }
        });
        $('input[name=key]').click(function(){
            if($(this).attr("checked")==true){
                $(this).parent().next().children('input').removeAttr ("disabled");
                $(this).parent().next().next().next().children('input').removeAttr ("disabled");
            }else{
                $(this).parent().next().children('input').attr("disabled",true);
                $(this).parent().next().next().next().children('input').attr("disabled",true);
                
            }
        });
    });

</script>
<include file="Public:footer" />
